package com.jfinal.ext.ueditor.result;

import com.jfinal.ext.ueditor.entity.FileInfo;
import org.jetbrains.annotations.NotNull;

/**
 * @author 江理_网猿 (timor)
 * @date 2020/10/8 0008
 */
public class UploadResult extends RetResult {
    private String url = null;
    private String name = null;
    private String title = null;
    private String original = null;

    protected UploadResult(boolean success) {
        super(success);
    }

    protected UploadResult(@NotNull String message) {
        super(message);
    }


    public static UploadResult by(boolean success, String message) {
        if (success) {
            return success();
        }
        return failure(message);
    }

    public static UploadResult failure() {
        return new UploadResult(false);
    }

    public static UploadResult failure(@NotNull String message) {
        return new UploadResult(message);
    }

    public static UploadResult success() {
        return new UploadResult(true);
    }

    public static UploadResult success(@NotNull FileInfo fileInfo) {
        final UploadResult result = success();

        result.setUrl(fileInfo.getUrl());
        result.setName(fileInfo.getNewName());
        result.setTitle(fileInfo.getOriginalName());
        result.setOriginal(fileInfo.getOriginalName());

        return result;
    }

    public static UploadResult success(@NotNull String url,
                                       @NotNull String newName,
                                       @NotNull String originalName) {
        final UploadResult result = success();

        result.setUrl(url);
        result.setName(newName);
        result.setTitle(originalName);
        result.setOriginal(originalName);

        return result;
    }



    public String getUrl(){
        return url;
    }

    public void setUrl(String url){
        this.url = url;
    }


    public String getName(){
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getTitle(){
        return title;
    }

    public void setTitle(String title){
        this.title = title;
    }


    public String getOriginal(){
        return original;
    }

    public void setOriginal(String original){
        this.original = original;
    }

}
